package com.zjl.redis.第06章_SpringBoot整合redis;

import io.lettuce.core.RedisClient;
import io.lettuce.core.RedisFuture;
import io.lettuce.core.RedisURI;
import io.lettuce.core.api.StatefulRedisConnection;
import io.lettuce.core.api.async.RedisAsyncCommands;
import io.lettuce.core.api.sync.RedisCommands;

import java.util.List;
import java.util.concurrent.ExecutionException;

/**
 * ClassName: jar包2_lettuce
 * Package: com.zjl.redis.第06章_SpringBoot整合redis
 * Description:
 *
 * @Author 张蛟龙
 * @Create 2024/6/30 20:54
 * @Version 1.0
 */
public class C1_lettuce {

    public static void main(String[] args) throws ExecutionException, InterruptedException {

        //构建 配置
        RedisURI redis2 = RedisURI.builder()
                .redis("82.157.71.243",6379)//设置 ip 端口
                .withHost("82.157.71.243")//设置 ip
                .withPort(6379)//设置  端口
                .withAuthentication("default","er485g96er8")//设置 用户名密码
                .withPassword("er485g96er8")//设置 密码
                .build();

        //连接 reids
        RedisClient redisClient = RedisClient.create(redis2);
        StatefulRedisConnection<String, String> connect = redisClient.connect();

        //创建 操作类
        RedisCommands<String, String> sync = connect.sync();//同步的连接
        RedisAsyncCommands<String, String> async = connect.async();//异步的连接

        //同步的操作
        List<String> keys = sync.keys("*");
        System.out.println(keys);
        //异步的操作
        RedisFuture<String> stringRedisFuture = async.get("1");
        System.out.println(stringRedisFuture.get());

        connect.close();//关闭资源
        redisClient.shutdown();//关闭资源
    }
}
